import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lily
 * Date: 2024-10-28
 * Time: 21:33
 */
public class test_3 {
    static int N = (int) 1e4 + 10;
    static int[] sum = new int[N]; // sum[i] 表⽰ i 这个数的总和 static int[] f = new int[N];
    static int[] f = new int[N];
    static int[] g = new int[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int n = in.nextInt();
        int x = 0;
        for (int i = 0; i < n; i++) {
            x = in.nextInt();
            sum[x] += x;
        }
        for (int i = 1; i < N; i++) {
            f[i] = g[i - 1] + sum[i];
            g[i] = Math.max(g[i - 1], f[i - 1]);
        }
        System.out.println(Math.max(f[N - 1], g[N - 1]));
    }
}
